/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import vo.VOSubmission;

/**
 *
 * @author sbaldrich
 */
@Entity
@Table(name = "submission")
@NamedQueries(
{
    @NamedQuery(name = "Submission.findAll", query = "SELECT s FROM Submission s"),
    @NamedQuery(name = "Submission.findByIdSubmission", query = "SELECT s FROM Submission s WHERE s.idSubmission = :idSubmission"),
    @NamedQuery(name = "Submission.findByDate", query = "SELECT s FROM Submission s WHERE s.date = :date"),
    @NamedQuery(name = "Submission.findByLanguage", query = "SELECT s FROM Submission s WHERE s.language = :language"),
    @NamedQuery(name = "Submission.findByVerdict", query = "SELECT s FROM Submission s WHERE s.verdict = :verdict")
})
public class Submission implements Serializable
{

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "idSubmission")
    private Integer idSubmission;
    @Basic(optional = false)
    @Lob
    @Column(name = "code")
    private String code;
    @Basic(optional = false)
    @Column(name = "date")
    @Temporal(TemporalType.TIMESTAMP)
    private Date date;
    @Basic(optional = false)
    @Column(name = "language")
    private String language;
    @Basic(optional = false)
    @Column(name = "verdict")
    private String verdict;
    @JoinColumn(name = "idProblem", referencedColumnName = "idProblem")
    @ManyToOne(optional = false)
    private Problem problem;
    @JoinColumn(name = "idContest", referencedColumnName = "idContest")
    @ManyToOne
    private Contest contest;
    @JoinColumn(name = "idUser", referencedColumnName = "idUser")
    @ManyToOne(optional = false)
    private User user;

    public Submission()
    {
    }

    public Submission(Integer idSubmission)
    {
        this.idSubmission = idSubmission;
    }

    public Submission(Integer idSubmission, String code, Date date, String language, String verdict)
    {
        this.idSubmission = idSubmission;
        this.code = code;
        this.date = date;
        this.language = language;
        this.verdict = verdict;
    }

    public Submission(VOSubmission vo)
    {
        this.setCode(vo.getCode());
        this.setDate(vo.getDate());
        this.setIdSubmission(vo.getIdSubmission());
        this.setLanguage(vo.getLanguage());
        this.setVerdict(vo.getVerdict());
    }

    public Integer getIdSubmission()
    {
        return idSubmission;
    }

    public void setIdSubmission(Integer idSubmission)
    {
        this.idSubmission = idSubmission;
    }

    public String getCode()
    {
        return code;
    }

    public void setCode(String code)
    {
        this.code = code;
    }

    public Date getDate()
    {
        return date;
    }

    public void setDate(Date date)
    {
        this.date = date;
    }

    public String getLanguage()
    {
        return language;
    }

    public void setLanguage(String language)
    {
        this.language = language;
    }

    public String getVerdict()
    {
        return verdict;
    }

    public void setVerdict(String verdict)
    {
        this.verdict = verdict;
    }

    public Problem getProblem()
    {
        return problem;
    }

    public void setProblem(Problem problem)
    {
        this.problem = problem;
    }

    public Contest getContest()
    {
        return contest;
    }

    public void setContest(Contest contest)
    {
        this.contest = contest;
    }

    public User getUser()
    {
        return user;
    }

    public void setUser(User user)
    {
        this.user = user;
    }

    @Override
    public int hashCode()
    {
        int hash = 0;
        hash += (idSubmission != null ? idSubmission.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object)
    {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Submission))
        {
            return false;
        }
        Submission other = (Submission) object;
        if ((this.idSubmission == null && other.idSubmission != null) || (this.idSubmission != null && !this.idSubmission.equals(other.idSubmission)))
        {
            return false;
        }
        return true;
    }

    @Override
    public String toString()
    {
        return "entities.Submission[idSubmission=" + idSubmission + "]";
    }

    public VOSubmission getVO()
    {
        return new VOSubmission(this);
    }
}
